package com.SmartEdu.controller;

import com.SmartEdu.Credentials;
import com.SmartEdu.dto.User;
import com.SmartEdu.register.VerifyCodeGenerator;
import com.SmartEdu.result.Result;
import com.SmartEdu.service.UserService;
import com.SmartEdu.vo.RestBean;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/auth")
@Tag(name = "用户登录",description = "处理用户登录相关数据")
public class LoginController {
    @Resource
    UserService service;
    @Operation(summary = "登录接口" )
    @GetMapping("/login")
    public String login(String email, String password, HttpServletRequest request){
        request.removeAttribute("email");
        request.removeAttribute("password");
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper
                .eq("email",email)
                .eq("password",password);
        User user = service.getOne(queryWrapper);
        if(user!=null){
            return  RestBean.success(user.getIdentity()).asJsonString();
        }else{
            return RestBean.failure(403,"邮箱或者密码错误").asJsonString();
        }
    }


    //忘记密码
}
